﻿using System;

namespace FourWayClimbingDemo
{
    class Program
    {
        static  void Main(string[] args)
        {
            Console.WriteLine("    *************************************************************");
            Console.WriteLine("    *                             四路爬                        *");
            Console.WriteLine("    *                      Copyright 2021 凌风游                *");
            Console.WriteLine("    *     https://gitee.com/lkj1420428992/four-way-climbing     *");
            Console.WriteLine("    *************************************************************");
            Console.WriteLine();
            Console.WriteLine("    在4X4的棋盘，每人共4颗棋子，沿横向或纵向每次走一格，");
            Console.WriteLine("    当双方棋子在相邻格时，则一家棋子跳过该子落在另一格种，");
            Console.WriteLine("    则对家该子被吃掉（就相当于从该棋子头上跳过去，则该子就背吃掉）。 ");
            Console.WriteLine("    直到吃掉全部棋子则胜利。");
            Console.WriteLine("    ");
            Console.WriteLine("    玩法：exit:退出,restart:重新开始  ");
            Console.WriteLine("    光标处输入： 1,1(对应棋子的坐标)，然后按上下左右键，分别对应相应的移动。");
            Console.WriteLine("   ");
            Console.WriteLine("   ");
            Console.WriteLine("   ");

            bool isExit = false;
            FwcPlay fwc = new FwcPlay();
            fwc.Init();
            fwc.ShowChessBorad();
            string msg = string.Empty;
            while (!isExit) {

                if (fwc.IsAutoPlay())
                {
                    fwc.PlayChess();
                }
                else {
                    var key = Console.ReadKey();

                    switch (key.Key)
                    {
                        case ConsoleKey.Enter:
                            if (msg == "exit")
                            {
                                isExit = true;
                            }
                            else if (msg == "restart")
                            {
                                fwc.ReStart();
                            }
                            msg = string.Empty;
                            break;
                        case ConsoleKey.UpArrow:
                            fwc.PlayChess(msg, Chess.Dir.TOP);
                            msg = string.Empty;
                            break;
                        case ConsoleKey.DownArrow:
                            fwc.PlayChess(msg, Chess.Dir.BOTTOM);
                            msg = string.Empty;
                            break;
                        case ConsoleKey.LeftArrow:
                            fwc.PlayChess(msg, Chess.Dir.LEFT);
                            msg = string.Empty;
                            break;
                        case ConsoleKey.RightArrow:
                            fwc.PlayChess(msg, Chess.Dir.RIGHT);
                            msg = string.Empty;
                            break;
                        default:
                            msg += key.KeyChar;
                            break;
                    }
                }                
            }
        }
    }
}
